// miniprogram/pages/my-book/my-book.js
const MAX_LIMIT = 10
const db = wx.cloud.database()
Page({
  data: {
    bookList:[],
    isClick: true,
  },
  onLoad: function (options) {
    this._getListByMiniprogram()

  },
  _getListByCloudFn(){
    wx.showLoading({
      title: '加载中',
    })
    wx.cloud.callFunction({
      name:'book',
      data:{
        start:this.data.bookList.length,
        cound:MAX_LIMIT,
        $url:'getListByOpenid'
      }
    }).then(res=>{
      this.setData({
        bookList:this.data.bookList.concat(res.result)
      })
      wx.hideLoading()
    })
  },
  _getListByMiniprogram(){
    wx.showLoading({
      title: '加载中',
    })
    db.collection('book').skip(this.data.bookList.length)
    .limit(MAX_LIMIT).orderBy('createTime','desc').get().then(res=>{
      let _booklist = res.data
      for(let i=0,len=_booklist.length;i<len;i++){
        _booklist[i].createTime = _booklist[i].createTime.toString()
      }
      this.setData({
        bookList:this.data.bookList.concat(_booklist)
      })
      wx.hideLoading()
    })
  },
  toCancel(){
    
    this.setData({
      isClick: false
    })
    }
})


